{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting torch\n",
      "  Using cached torch-1.11.0-cp37-none-macosx_10_9_x86_64.whl (129.9 MB)\n",
      "Requirement already satisfied: typing-extensions in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from torch) (4.0.1)\n",
      "Installing collected packages: torch\n",
      "Successfully installed torch-1.11.0\n",
      "\u001b[33mWARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.\n",
      "You should consider upgrading via the '/Users/ian/Workshop/tw_mahjong/ENV/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n",
      "Requirement already satisfied: g2pw in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (0.0.5)\n",
      "Requirement already satisfied: tqdm in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from g2pw) (4.63.0)\n",
      "Requirement already satisfied: transformers in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from g2pw) (4.17.0)\n",
      "Requirement already satisfied: sacremoses in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (0.0.49)\n",
      "Requirement already satisfied: tokenizers!=0.11.3,>=0.11.1 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (0.11.6)\n",
      "Requirement already satisfied: regex!=2019.12.17 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (2022.3.15)\n",
      "Requirement already satisfied: huggingface-hub<1.0,>=0.1.0 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (0.4.0)\n",
      "Requirement already satisfied: importlib-metadata in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (4.10.1)\n",
      "Requirement already satisfied: numpy>=1.17 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (1.21.5)\n",
      "Requirement already satisfied: pyyaml>=5.1 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (6.0)\n",
      "Requirement already satisfied: requests in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (2.27.1)\n",
      "Requirement already satisfied: packaging>=20.0 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (21.3)\n",
      "Requirement already satisfied: filelock in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from transformers->g2pw) (3.6.0)\n",
      "Requirement already satisfied: typing-extensions>=3.7.4.3 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from huggingface-hub<1.0,>=0.1.0->transformers->g2pw) (4.0.1)\n",
      "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from packaging>=20.0->transformers->g2pw) (3.0.7)\n",
      "Requirement already satisfied: zipp>=0.5 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from importlib-metadata->transformers->g2pw) (3.7.0)\n",
      "Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from requests->transformers->g2pw) (2.0.12)\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from requests->transformers->g2pw) (1.26.9)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from requests->transformers->g2pw) (3.3)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from requests->transformers->g2pw) (2021.10.8)\n",
      "Requirement already satisfied: joblib in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from sacremoses->transformers->g2pw) (1.1.0)\n",
      "Requirement already satisfied: click in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from sacremoses->transformers->g2pw) (8.0.3)\n",
      "Requirement already satisfied: six in /Users/ian/Workshop/tw_mahjong/ENV/lib/python3.7/site-packages (from sacremoses->transformers->g2pw) (1.16.0)\n",
      "\u001b[33mWARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.\n",
      "You should consider upgrading via the '/Users/ian/Workshop/tw_mahjong/ENV/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install torch\n",
    "!pip install g2pw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Some weights of the model checkpoint at bert-base-chinese were not used when initializing G2PW: ['cls.predictions.transform.LayerNorm.bias', 'cls.seq_relationship.weight', 'cls.predictions.transform.LayerNorm.weight', 'cls.predictions.transform.dense.bias', 'cls.predictions.decoder.weight', 'cls.predictions.transform.dense.weight', 'cls.predictions.bias', 'cls.seq_relationship.bias']\n",
      "- This IS expected if you are initializing G2PW from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
      "- This IS NOT expected if you are initializing G2PW from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
      "Some weights of G2PW were not initialized from the model checkpoint at bert-base-chinese and are newly initialized: ['pos_classifier.bias', 'char_descriptor.weight', 'second_order_descriptor.weight', 'descriptor_bias.weight', 'classifier.bias', 'classifier.weight', 'pos_classifier.weight']\n",
      "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
     ]
    }
   ],
   "source": [
    "from g2pw import G2PWConverter\n",
    "conv = G2PWConverter()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)\n",
      "[W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[['ㄕㄤ4',\n",
       "  'ㄒㄧㄠ4',\n",
       "  'ㄑㄧㄥ3',\n",
       "  'ㄐㄧ4',\n",
       "  'ㄕㄨ4',\n",
       "  'ㄖㄣ2',\n",
       "  'ㄩㄢ2',\n",
       "  'ㄐㄧㄠ4',\n",
       "  'ㄓㄥ4',\n",
       "  None,\n",
       "  None,\n",
       "  'ㄧ2',\n",
       "  'ㄑㄧ4']]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentence = '上校請技術人員校正FN儀器'\n",
    "conv(sentence)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)\n",
      "[W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[['ㄧㄣ2', 'ㄏㄤ2'], ['ㄒㄧㄥ2', 'ㄉㄨㄥ4']]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentences = ['銀行', '行動']\n",
    "conv(sentences)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "3eaaf63e29c710c70472a7a883479281f48fb280cd7f1b56f659c98be7d30927"
  },
  "kernelspec": {
   "display_name": "Python 3.7.9 ('ENV': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
